//
//  MBUploadPictureDetailCell.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/23.
//

import Foundation
import YYText
import SnapKit


class MBUploadPictureDetailCell: MBDCommonCell {

    var titleLabel : YYLabel!
    var codeImageView : UIImageView!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initialize()
    }
    
    func initialize() {
        titleLabel = YYLabel()
        self.contentView.addSubview(titleLabel)
        
        codeImageView = UIImageView()
        self.contentView.addSubview(codeImageView)
        codeImageView.image = UIImage(named: "ico_qrcode")

        titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(self.contentView)
            make.left.equalTo(15)
            make.right.equalTo(-30)
            make.height.equalTo(18)
        }
        
        codeImageView.snp.makeConstraints { make in
            make.centerY.equalTo(self.contentView)
            make.right.equalTo(self.rightArrowImage.snp.left).offset(-20)
            make.size.equalTo(CGSizeMake(25, 25))
        }

    }
    
    var title : String? {
        didSet {
            
            let titleAttributeString = NSMutableAttributedString(string: self.title ?? "")
            titleAttributeString.yy_font = UIFont.systemFont(ofSize: 14)
            titleAttributeString.yy_color = UIColor(colorHex: 0x333333)
            titleAttributeString.yy_lineSpacing = 6

            let userNamecontainer = YYTextContainer()
            let userNameWidth = CGRectGetWidth(UIScreen.main.bounds) - 30
            userNamecontainer.size = CGSizeMake(userNameWidth , CGFLOAT_MAX)
            userNamecontainer.maximumNumberOfRows = 0

            let titleLayout = YYTextLayout(container: userNamecontainer, text: titleAttributeString)

            titleLabel.textLayout = titleLayout
            
            titleLabel.snp.updateConstraints { make in
                let height = titleLayout!.textBoundingSize.height
                make.height.equalTo(height)
            }
        }
        
        willSet {
        }
    }
}
